﻿using RpcHelper.Config;
using RpcSync.Service.Interface;

namespace RpcSync.Service.Config
{
    [RpcClient.Attr.ClassLifetimeAttr(RpcClient.Attr.ClassLifetimeType.单例)]
    internal class TranConfig : ITranConfig
    {
        public TranConfig(IConfigCollect config)
        {
            config.RefreshEvent += _InitConfig;
            this.TranRollbackRetryNum = config.GetValue<short>("tran:RollbackRetryNum", 3);
            this.TranCommitRetryNum = config.GetValue<short>("tran:CommitRetryNum", 3);
        }
        private void _InitConfig(IConfigCollect config, string name)
        {
            if (name == "tran" || name.StartsWith("tran:"))
            {
                this.TranRollbackRetryNum = config.GetValue<short>("tran:RollbackRetryNum", 3);
                this.TranCommitRetryNum = config.GetValue<short>("tran:CommitRetryNum", 3);
            }
        }

        /// <summary>
        /// 事务回滚重试数
        /// </summary>
        public short TranRollbackRetryNum { get; private set; } = 3;

        public short TranCommitRetryNum { get; private set; } = 3;
    }
}
